﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace HYCodeBase.StringUtility
{
	public class SimpleChineseUtilityMethod
	{
		public static bool IfIsSimpleChinese(string input, bool ifTotal = false)
		{
			return !string.IsNullOrWhiteSpace(input) && (ifTotal ? SimpleChineseUtilityMethod.m_totalSimpleChineseRegex : SimpleChineseUtilityMethod.m_partSimpleChinesePatternRegex).IsMatch(input);
		}

		public static List<List<char>> GetFirstPYList(string input)
		{
			List<List<char>> list = new List<List<char>>();
			if (string.IsNullOrWhiteSpace(input))
			{
				return list;
			}
			foreach (object obj in SimpleChineseUtilityMethod.m_partSimpleChinesePatternRegex.Matches(input))
			{
				Capture capture = (Match)obj;
				List<char> list2 = new List<char>();
				list.Add(list2);
				string value = capture.Value;
				for (int i = 0; i < value.Length; i++)
				{
					char? simpleChinesFirstPY = SimpleChineseUtilityMethod.GetSimpleChinesFirstPY(value[i].ToString());
					if (simpleChinesFirstPY != null)
					{
						list2.Add(simpleChinesFirstPY.Value);
					}
				}
			}
			return list;
		}

		private static char? GetSimpleChinesFirstPY(string input)
		{
			try
			{
				byte[] bytes = Encoding.Default.GetBytes(input);
				int num = (int)bytes[0];
				int num2 = (int)bytes[1];
				long num3 = (long)(num * 256 + num2);
				if (num3 >= 45217L && num3 <= 45252L)
				{
					return new char?('A');
				}
				if (num3 >= 45253L && num3 <= 45760L)
				{
					return new char?('B');
				}
				if (num3 >= 45761L && num3 <= 46317L)
				{
					return new char?('C');
				}
				if (num3 >= 46318L && num3 <= 46825L)
				{
					return new char?('D');
				}
				if (num3 >= 46826L && num3 <= 47009L)
				{
					return new char?('E');
				}
				if (num3 >= 47010L && num3 <= 47296L)
				{
					return new char?('F');
				}
				if (num3 >= 47297L && num3 <= 47613L)
				{
					return new char?('G');
				}
				if (num3 >= 47614L && num3 <= 48118L)
				{
					return new char?('H');
				}
				if (num3 >= 48119L && num3 <= 49061L)
				{
					return new char?('J');
				}
				if (num3 >= 49062L && num3 <= 49323L)
				{
					return new char?('K');
				}
				if (num3 >= 49324L && num3 <= 49895L)
				{
					return new char?('L');
				}
				if (num3 >= 49896L && num3 <= 50370L)
				{
					return new char?('M');
				}
				if (num3 >= 50371L && num3 <= 50613L)
				{
					return new char?('N');
				}
				if (num3 >= 50614L && num3 <= 50621L)
				{
					return new char?('O');
				}
				if (num3 >= 50622L && num3 <= 50905L)
				{
					return new char?('P');
				}
				if (num3 >= 50906L && num3 <= 51386L)
				{
					return new char?('Q');
				}
				if (num3 >= 51387L && num3 <= 51445L)
				{
					return new char?('R');
				}
				if (num3 >= 51446L && num3 <= 52217L)
				{
					return new char?('S');
				}
				if (num3 >= 52218L && num3 <= 52697L)
				{
					return new char?('T');
				}
				if (num3 >= 52698L && num3 <= 52979L)
				{
					return new char?('W');
				}
				if (num3 >= 52980L && num3 <= 53688L)
				{
					return new char?('X');
				}
				if (num3 >= 53689L && num3 <= 54480L)
				{
					return new char?('Y');
				}
				if (num3 >= 54481L && num3 <= 55289L)
				{
					return new char?('Z');
				}
			}
			catch
			{
			}
			return null;
		}

		private const string m_strTotalSimpleChinesesPattern = "^[\\u4e00-\\u9fa5]+$";

		private const string m_strPartSimpleChinesePattern = "[\\u4e00-\\u9fa5]+";

		private static Regex m_totalSimpleChineseRegex = new Regex("^[\\u4e00-\\u9fa5]+$");

		private static Regex m_partSimpleChinesePatternRegex = new Regex("[\\u4e00-\\u9fa5]+");
	}
}
